package ACM.shence;

/**
 * @Author wwk
 * @DATE 2022/8/26 20:34
 */
import java.util.Scanner;

public class third {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];

        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {

                max = Math.max(max, nums[i]+nums[j]-(j-i));
            }

        }

        System.out.println(max);
    }


}
